#encoding=utf-8

import os,sys,shutil,linecache;

select = """
请选择你要添加的项目类型\r\n
    1.有家属有加项
    2.有家属无加项
    3.有加项无家属
    4.无加项无家属\r\n
"""

# 项目标识
project_name = raw_input("请输入项目的名字:")
# 公司名字
account_name = raw_input("请输入公司的名字:")
# 项目类型
project_type = raw_input(select+"请输入:")

dirlist = ['doc','public','test','routes']
template = "../"
admindir = "e:/work/"
admintpl = 'admin_sunc.php'
templatedir = "config"
# 创建一个项目
def createProject(proname,protype=1):
    name = dirlist[int(protype)-1]
    if(os.path.exists(template+proname)):
        print("文件目录"+proname+"已经存在")
        os._exit(-1)
    try:
        shutil.copytree(template+name,template+proname)
        shutil.copyfile(admindir+admintpl,admindir+"admin_"+project_name)
    except Exception as e:
        print("error:复制目录失败"+e)

# 编辑模板文件
def editTemplate(file,line,data):
    lists = linecache.getlines(file)
    length = len(lists)
    lists[3] = data;
    print(lists)
    s = "".join(lists)
    linecache.clearcache()
    with open(file,'w+') as fp:
        fp.write(s)
        fp.close()
    pass

#替换标题
editTemplate('./index.html',4,''.join([" "*4])+"<title>哈哈你被替换了</title>\r")
# 替换meta
editTemplate('./index.html',4,''.join([" "*4])+"<title>哈哈你被替换了</title>\r")
editTemplate('./index.html',4,''.join([" "*4])+"<title>哈哈你被替换了</title>\r")

# 替换logo
editTemplate('./index.html',4,''.join([" "*4])+"<title>哈哈你被替换了</title>\r")
editTemplate('./index.html',4,''.join([" "*4])+"<title>哈哈你被替换了</title>\r")

# 替换标识
# createProject(project_name,project_type)
print(project_name,account_name,project_type)